<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //一维数组遍历
      var arr1 = [1, 2, 3, 4, 5];
      //for循环
      for (var i = 0; i < arr1.length; i++) {
        console.log(arr1[i]);
      }
      //for in循环
      for (var i in arr1) {
        console.log(arr1[i]);
      }
      //forEach
      arr1.forEach(function (value, index) {
        console.log(index, value);
      });
      arr1.forEach(function (value) {
        console.log(value);
      });

      //二维数组遍历
      var arr2 = [
        [1, 2, 3],
        [4, 5, 6],
        [7, 8, 9],
      ];
      //for
      for (var i = 0; i < arr2.length; i++) {
        //先遍历行
        console.log(arr2[i]);
        //再遍历列
        for (var j = 0; j < arr2[i].length; j++) {
          console.log(arr2[i][j]);
        }
      }
      //for in
      for (var i in arr2) {
        for (var j in arr2[i]) {
          console.log(arr2[i][j]);
        }
      }
      //forEach
      arr2.forEach(function (v) {
        v.forEach(function (v1) {
          console.log(v1);
        });
      });
    </script>
  </body>
</html>
